#ifndef __OBJCACHE_H__
#define __OBJCACHE_H__
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>

#include <list.h>
#include <spinlock.h>
#include <util.h>

#define SLAB_SIZE PAGE_SIZE
#define SLAB_MIN_HEADER_SIZE (32)
#define SLAB_MAX_OBJECT_SIZE (PAGE_SIZE / 4)

struct objcache;
typedef union slab slab_t;

typedef struct objcache {
    size_t osize;
    list_t slabs;
    slab_t* last_free;
    spinlock_t lock;
} objcache_t;

void objcache_init(objcache_t* oc, size_t osize, bool prime);
void* objcache_alloc();
bool objcache_free(objcache_t* oc, void* obj);

#endif /* __OBJCACHE_H__ */
